package com.java.controller.api;


import com.java.pojo.entity.BorrowInfo;
import com.java.result.Result;
import com.java.service.BorrowInfoService;
import com.java.service.BorrowerService;
import com.java.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-07-08
 */

@Api("借款信息表")
@RestController
@RequestMapping("/api/core/borrowInfo")
public class BorrowInfoController {


    @Resource
    private BorrowInfoService borrowInfoService;

    @ApiOperation("获取借款额度")
    @GetMapping("/auth/getAmount")
    public Result getAmount(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        BigDecimal decimal = borrowInfoService.getAmount(userId);
        return Result.ok(decimal);
    }

    @ApiOperation("保存借款申请")
    @PostMapping("/auth/BorrowerInfoSave")
    public Result BorrowerInfoSave(@RequestBody BorrowInfo BorrowInfo, HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowInfoService.saveBorrowerInfo(BorrowInfo,userId);
        return Result.ok();
    }

    @ApiOperation("获取借款申请审批状态")
    @GetMapping("/auth/getBorrowAuthStatus")
    public Result getBorrowAuthStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        Integer status =  borrowInfoService.getBorrowerAuthStatus(userId);
        return Result.ok(status);
    }


}

